package com.shiguiwu.springmybatis.app.controller;

import cn.hutool.json.JSONUtil;
import com.shiguiwu.springmybatis.app.dto.RequestUser;
import com.shiguiwu.springmybatis.app.entity.User;
import com.shiguiwu.springmybatis.mybatis.Book;
import com.shiguiwu.springmybatis.app.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 用户控制层
 * @author: stone
 * @date: Created by 2021/8/4 21:59
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.app.controller
 */
@RestController
@Slf4j
public class UserController {
    @Autowired
    private UserService myUserService;

    /**
     * showdoc
     * @catalog 用户接口/添加用户
     * @title 用户登录
     * @description 用户登录的接口
     * @method POST
     * @url https://127.0.0.1:8080/home/user/login
     * @header token 可选 string 设备token
     * @param username 必选 string 用户名
     * @param password 必选 string 密码
     * @param name 可选 string 用户昵称
     * @param taskInfo 可选 object 用户昵称
     * @param taskInfo.taskId string 任务id
     * @param taskInfo.nodeId string 节点id
     * @param taskInfo.taskName string 任务名称
     * @param taskInfo.lastNodeId string 上一个节点id
     * @param taskInfo.lastTaskId string 上一个任务id
     * @param taskInfo.approvals array 审批类型
     * @param taskInfo.approvals.approvalId string 子系统审批id
     * @param taskInfo.approvals.approvalType string 审批类型
     * @param taskInfo.approvals.userType string 用户类型copy或者approval
     * @param taskInfo.approvals.sort integer 排序
     * @param taskInfo.approvals.approvalUsers array 审批用户列表
     * @param taskInfo.approvals.approvalUsers.userId string 审批用户id
     * @param taskInfo.approvals.approvalUsers.userName string 审批用户id
     * @param taskInfo.approvals.approvalUsers.platformTaskApproveId string 子系统审批id
     * @param taskInfo.approvals.approvalUsers.userId string 审批用户id

     * @json_param {"instanceId": "test_3869189f59e7", "instanceName": "普通数据申请","flowId": "test_4ed2c6c33ce4", "status": "RUNNING",   "applyUserId":"test_a7b9fe47586c","taskInfo": {"taskId":"test_b6aebd595e11","nodeId": "test_7a311c9b359e", "taskName": "任务名称", "lastNodeId": "test_dc257511336f", "lastTaskId": "test_3d4598bc254f",   "approvals": [   {  "approvalId": "test_3e3f6dd747e0",  "approvalUsers": [ {  "platformTaskApproveId": "test_38c033ce936f",   "userId": "test_ec69e6cb1e85",   "userName": "test_c6a6c2443533"   }     ],   "approvalType": "AND", "userType": "APPROVAL",   "sort": 1  }   ]   }}
     * @return {"error_code":0,"data":{"uid":"1","username":"12154545","name":"吴系挂","groupid":2,"reg_time":"1436864169","last_login_time":"0"}}
     * @return_param groupid int 用户组id
     * @return_param name string 用户昵称
     * @remark 这里是备注信息
     * @number 99
     */
    @PostMapping("/user")
    public String add() throws Exception {
        long l = System.currentTimeMillis();
        myUserService.f();
        log.error("本次的访问耗时==================> {}", (System.currentTimeMillis() - l)/1000);

        return "success";
    }


    /**
     * @api {POST} /userTest test
     * @apiVersion 1.0.0
     * @apiGroup UserController
     * @apiName test
     * @apiDescription 22222
     * @apiParam (请求体) {Number} id
     * @apiParam (请求体) {String} username
     * @apiParam (请求体) {String} password
     * @apiParam (请求体) {String} phone
     * @apiParam (请求体) {String} gender
     * @apiParam (请求体) {String} other1
     * @apiParam (请求体) {Number} createTime
     * @apiParam (请求体) {Number} updateTime
     * @apiParam (请求体) {Number} version
     * @apiParam (请求体) {Number} deleted
     * @apiParamExample 请求体示例
     * {"password":"ISuKnjU","deleted":4908,"gender":"NbE5U3n","phone":"F4yVk","createTime":3713902151842,"updateTime":253898622954,"id":4303,"other1":"6e7TLKDzSk","version":4588,"username":"3HTq6cP"}
     * @apiSuccess (响应结果) {Number} id
     * @apiSuccess (响应结果) {String} username
     * @apiSuccess (响应结果) {String} password
     * @apiSuccess (响应结果) {String} phone
     * @apiSuccess (响应结果) {String} gender
     * @apiSuccess (响应结果) {String} other1
     * @apiSuccess (响应结果) {Number} createTime
     * @apiSuccess (响应结果) {Number} updateTime
     * @apiSuccess (响应结果) {Number} version
     * @apiSuccess (响应结果) {Number} deleted
     * @apiSuccessExample 响应结果示例
     * {"password":"8xHL","deleted":3906,"gender":"bct9Ra","phone":"kl8","createTime":1836719729365,"updateTime":2415141664407,"id":2779,"other1":"HsU","version":4509,"username":"A7QIT"}
     */
    @PostMapping("/userTest")
    public User test(@RequestBody User user, @RequestBody Book book) {

        log.info("user 对象 {} ，book对象 {}", JSONUtil.toJsonStr(user), JSONUtil.toJsonStr(book));
        return user;
    }

    
    /**
     * showdoc
     * @catalog 用户接口/修改密码
     * @title 接口名称
     * @description 接口描述
     * @method POST
     * @url http://127.0.0.1:8080/pwd
     * @header token 可选 string 设备token
     * @param userId 可选 string 用户编号
     * @param password 可选 string 用户密码
     * @json_param {}
     * @return
     * @remark pwd 
     * @number 99
     * @create 2023/2/6 15:59
     */
    @PostMapping("/pwd")
    public String pwd(@RequestBody RequestUser dto) {
        log.info("============> {}", JSONUtil.toJsonStr(dto));
        return JSONUtil.toJsonStr(dto);
    }
}
